<template>
    <div>
        <Card>
            <p slot="title">
                修改登录密码
            </p>
            <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
                <FormItem label="原密码" prop="oPass">
                    <Input v-model="formValidate.oPass" type="password" placeholder="请输入登录密码" class="wid300"/>
                </FormItem>
                <FormItem label="新密码" prop="nPass">
                    <Input v-model="formValidate.nPass" type="password" placeholder="请输入新密码" class="wid300"/>
                </FormItem>
                <FormItem label="确认密码" prop="rPass">
                    <Input v-model="formValidate.rPass" type="password" placeholder="请确认新密码" class="wid300"/>
                </FormItem>
                <FormItem>
                    <Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
                    <Button @click="handleReset('formValidate')" style="margin-left: 8px">重置</Button>
                </FormItem>
            </Form>
        </Card>
    </div>
</template>
<script>
    import {get_local_user_id} from '@/utils/config_common.js';
    export default {
        data () {
            const checkPassword = (rule, value, callback) => {
                if (value !== this.formValidate.nPass) {
                    callback(new Error('两次输入密码不一致!'));
                } else {
                    callback();
                }
            }
            return {
                formValidate: {
                    user_id:get_local_user_id(),
                    oPass: '',
                    nPass: '',
                    rPass: ''
                },
                ruleValidate: {
                    oPass: [
                        {required: true, message: '请输入原密码', trigger: 'blur'},
                    ],
                    nPass: [
                        {required: true, message: '请输入新密码', trigger: 'blur'},
                    ],
                    rPass: [
                        {required: true, message: '请再次输入新密码', trigger: 'blur'},
                        {validator: checkPassword, trigger: 'blur'},
                        {validator: checkPassword, trigger: 'change'}
                    ]
                }
            };
        },
        methods: {
            handleSubmit (name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let opts = {
                            url: `${this.$hostUrl.nodehost}${this.$configApi.pass.url}`,
                            method: this.$configApi.pass.method
                        };
                        let params = this.formValidate;
                        this.$axios({
                            method: opts.method,
                            url: opts.url,
                            data: params
                        }).then(res => {
                            res = res.data;
                        });
                    }
                });
            },
            handleReset (name) {
                this.$refs[name].resetFields();
            },
            // 修改密码
            updatePass () {

            }
        }
    };
</script>
<style>
</style>


